/*
* @Time    : 2018/1/19 10:52
* @Author  : xincheng.zhao
* @Software: PyCharm
*/
$(document).ready(function () {
    $.ajax({
        url: '/get_reason',
        method: 'get',
        async: false,
        dataType: 'JSON',
        success: function (data) {
            for (i = 0; i < data.length; i++) {
                if (data[i].type == 'T') {
                    continue
                }
                $("#select").append('<option value="' + data[i].id + '"><div><span>' + data[i].type + "-->" + data[i].events + '</span></div></option>')
            }
        }
    })


    $('#select').change(function () {
        if (this == 0) {
            return false
        }
        $.ajax({
            url: '/reason_fault',
            method: 'get',
            data: 'id=' + $('#select').val(),
            success: function (data) {
                $('#ev_x').empty()
                $('#ev_m').empty()
                $('#Modal').modal('show')
                data = data.split(';')
                j = -1
              for (i = 0; i < data.length; i++) {
                    // for(k=0;k<=5;k++) {
                        if (data[i] == 'm') {
                            continue
                        } else if (data[i] == 'x') {
                            j = i + 1
                            continue
                        }
                        if (i == j) {
                            j = ++j
                            $("#ev_m").append(data[i] + '<br>')
                            continue
                        }
                        $("#ev_x").append(data[i] + '<br>')
                    // }
                }
            },
        })
    })


})

